<?
$editpage = $_POST['path'];
if ($editpage[0]!='/') $editpage='/'.$editpage;
unset($_POST['path']);
include_once(engine.'/classes/file.class.php');
$page=new file(root.$editpage);
$content=$page->getContent();
if (empty($_POST)) {
	preg_match_all('/\$this-\>([a-z,0-9]*)[\s]*=[\s]*([\'"])(.*)(\2);/Uis',$content,$matches);
	//print_r($matches);
	//die();
	echo 'var out=Array();';
	foreach ($matches[1] as $key=>$val) {
		echo 'out[\''.$val.'\']="'.str_replace("\n",'\n',str_replace('"','\"',str_replace('\"','"',$matches[3][$key]))).'"; ';
		
	}
} else {
	foreach ($_POST as $key=>$val) {
		preg_match_all('/\$this-\>'.$key.'[\s]*=[\s]*([\'"])(.*)(\1);/Uis',$content,$matches);
		//print_r($matches);
		//die();
		if (empty($matches[0]) && !empty($val)) {
			if (strpos($content,'?>')==0) $content="<?\n?>\n".$content;
			$content=str_replace('?>',"\$this->".$key." = '".str_replace('\"','"',str_replace('<@#>','&',$val))."';\n?>",$content);
		} else {
			$content=str_replace($matches[0],"\$this->".$key." = '".str_replace('\"','"',str_replace('<@#>','&',$val))."';",$content);
		}
	}
	if ($page->putContent($content)) die('yes'); else die('Не удаётся сохранить страницу, проверьте права!');	
}
?>